package com.esun.cheetah.biz.personal.personalcommunicater;

import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import android.os.Handler;

import com.esun.cheetah.biz.personal.personalinfo.UserInfo;
import com.esun.cheetah.config.BizCode;

import com.esun.cheetah.config.Key;
import com.esun.cheetah.network.AbsInferiorityCommunicater;
import com.esun.util.log.EDebug;

/**
 * 
 * @Package com.esun.cheetah.biz.personal.personalcommunicater.LoggedinrefreshCommunicater
 * @ClassName: LoggedinrefreshCommunicater
 * @Description: TODO(user send login information)
 * @author handy <br/>
 * @date create at 2012-7-31 下午3:11:01
 *
 */
public class LoggedinrefreshCommunicater extends AbsInferiorityCommunicater {

	private String status;// 状态
	private String msg;// 返回信息
	private String money;

	private String bindmobile;

	private Context context;

	public LoggedinrefreshCommunicater(Handler handler) {
		super(handler);

	}

	@Override
	public HashMap<String, String> comHashMap() {
		HashMap<String, String> hmJson = new HashMap<String, String>();
		hmJson.put(Key.KEY_ID, BizCode.BIZCODE_REFRESH);
		hmJson.put(Key.KEY_CK, UserInfo.getUserInfo().getCk());
		//
		return hmJson;
	}

	@Override
	public void getJsonContent(String serverRes) throws JSONException {

		JSONObject json = new JSONObject(serverRes);
		status = json.getString(Key.STATUS);
		msg = json.getString(Key.MSG);

		EDebug.o("msg---" + msg);
		EDebug.o("status---" + status);
		if (Key.TRUE.equals(status)) {
			JSONObject jsondata = new JSONObject(json.getString(Key.DATA));

			money = jsondata.getString("balance");
			EDebug.o("money---" + money);

			bindmobile = jsondata.getString("bindmobile");
			EDebug.o("bindmobile---" + bindmobile);
			saveUserInfo();
		}
	}

	private void saveUserInfo() {

		UserInfo.getUserInfo().setMoney(money);
		UserInfo.getUserInfo().setBindmobile(bindmobile);

	}

	public Context getContext() {
		return this.context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

}
